package com.ict.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ict.dao.SummaryDao;
import com.ict.model.Summary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by weiaquarius on 16/3/30.
 */
@Service
public class SummaryService implements SummaryServiceInt {

    @Autowired
    public SummaryDao dao;
    /**
     *
     * @param num
     * @return
     */
    public List<Summary> getLastSummary(Double insertTime, Short packageTppe, Long num){
        List<Summary> l = dao.getLastSummaryByNum(insertTime, packageTppe, num);
        return l;
    }

    public List<List<Summary>> getSquareSummary(JSONArray jsonArray){
        List<List<Summary>> l = new ArrayList<List<Summary>>();
        for(int i = 0;i < jsonArray.size();i++){
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            List<Summary> list = dao.getSquareSummary(jsonObject.getInteger("dr_latitude")*600000,jsonObject.getInteger("dr_longitude")*600000,jsonObject.getInteger("ul_latitude")*600000,jsonObject.getInteger("ul_longitude")*600000);
            l.add(list);
        }
        return l;
    }

    public int getSummaryCount(Double insertTime, Short packageTppe){
        try {
            return dao.getSummaryCount(insertTime,packageTppe);
        }catch (Exception e){
            e.printStackTrace();
            return -1;
        }
    }


}
